package com.demon.androidbasic.toast

import android.content.Context
import android.widget.Toast
import androidx.fragment.app.Fragment
import com.demon.androidbasic.toast.ToastUtils.Duration.LONG

/**
 * <p>
 * Toast工具类
 * </p>
 *
 * @author zhaozeyang
 * @since 2020/4/10
 */

fun Context.toast(content: String?, duration: Int = Toast.LENGTH_SHORT) {
    content?.let {
        if (duration == Toast.LENGTH_SHORT) {
            ToastUtils.showToast(this, it)
        } else {
            ToastUtils.showToast(this, it, LONG)
        }
    }
}

fun Context.toast(content: Int, duration: Int = Toast.LENGTH_SHORT) {
    if (duration == Toast.LENGTH_SHORT) {
        ToastUtils.showToast(this, content)
    } else {
        ToastUtils.showToast(this, content, LONG)
    }
}

fun Context.shortToast(content: String?) {
    toast(content)
}

fun Context.shortToast(content: Int) {
    toast(content)
}

fun Context.longToast(content: String?) {
    toast(content, Toast.LENGTH_LONG)
}

fun Context.longToast(content: Int) {
    toast(content, Toast.LENGTH_SHORT)
}

fun Fragment.shortToast(content: String?) {
    activity?.toast(content)
}

fun Fragment.shortToast(content: Int) {
    activity?.toast(content)
}

fun Fragment.longToast(content: String?) {
    activity?.toast(content, Toast.LENGTH_LONG)
}

fun Fragment.longToast(content: Int) {
    activity?.toast(content, Toast.LENGTH_LONG)
}